package net.atomarrow.controllers.converter;

import java.util.Arrays;

import net.atomarrow.util.StringUtil;

public class StringConverter implements IConverter {

    @Override
    public boolean canHandle(Class clazz) {
		return clazz == String.class;
	}

    @Override
    public <T> T converter(Object[] values, Class<T> clazz) throws Exception{
    	if(values==null){
    		return null;
    	}
    	if(values.length>1){
    		String result= StringUtil.listToString(Arrays.asList(values), ",");
    		if(result==null||result.isEmpty()){
    			return (T)result;
    		}
    		result = ","+result+",";
    		return (T) result;
    	}else{
    		Object value =values[0];
    		if(value==null){
    			return null;
    		}
    		return (T) value.toString();
    	}
    }
}
